package com.itheima.a08Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Test2 {
    public static void main(String[] args) {
        /*带有概率的随机抽取
        男生：70%
        女生：30%
         */
        //1.创建集合
        ArrayList<Integer> list=new ArrayList<>();
        //2.添加元素
        Collections.addAll(list,1,1,1,1,1,1,1);
        Collections.addAll(list,0,0,0);
        //3.打乱里面的顺序
        Collections.shuffle(list);
        //3.生成随机数
        Random r = new Random();
        int index = r.nextInt(list.size());
        int number = list.get(index);
        System.out.println(number);

        //创建两个集合
        ArrayList<String> boyList=new ArrayList<>();
        ArrayList<String> girlList=new ArrayList<>();
        //分别添加元素
        Collections.addAll(boyList,"喜洋洋","灰太狼","大笨蛋","小笨蛋","猪猪侠","唐僧","猴子");
        Collections.addAll(girlList,"白骨精","红太狼","大西瓜");
        if(number == 1){
            int boyindex = r.nextInt(boyList.size());
            String name = boyList.get(boyindex);
            System.out.println(name);
        }else{
            int girlindex = r.nextInt(girlList.size());
            String name = girlList.get(girlindex);
            System.out.println(name);
        }
    }
}
